package com.ctcemti.mdm.project.common.excelverifyhandler;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.ctcemti.mdm.project.sys.dao.OrgStationMapper;
import com.ctcemti.mdm.project.sys.entity.InfDisciplines;
import com.ctcemti.mdm.project.sys.entity.OrgStation;

import java.util.ArrayList;
import java.util.List;

public class ExcelVerifyHandlerForOrgstation implements IExcelVerifyHandler<OrgStation> {

    private List<String> listCode;

    private OrgStationMapper orgStationMapper;

    private List<InfDisciplines> list;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(OrgStation orgStation) {

        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult();

        if(listCode.size()<1){
            result.setMsg("工点类型不存在，请联系管理员添加");
            result.setSuccess(false);
            return result;
        }
        if(listCode.size()>0){
            if(!listCode.contains(orgStation.getType())){
                result.setMsg("该工点类型非法，请按照模板填写");
                result.setSuccess(false);
                return result;
            }
        }
        result.setSuccess(true);
        return result;
    }

    public ExcelVerifyHandlerForOrgstation(Object object,List<InfDisciplines> list){
        this.listCode = new ArrayList<String>();
        this.orgStationMapper = (OrgStationMapper) object;
        this.list = list;
        for(InfDisciplines infDisciplines:list){
            listCode.add(infDisciplines.getName());
        }

    }
}
